/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.facade.bean;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DecimalFormat;

import org.grayrabbit.pay.facade.enums.ErrorCodeEnum;
import org.grayrabbit.pay.facade.exception.PayClientException;

/**
 * 货币交易
 * 
 * @author wy
 * @version $Id: ClientMoney.java, v 0.1 2012-6-1 下午5:36:08 wy Exp $
 */
public class Money implements Serializable{

    /**  */
    private static final long serialVersionUID = 8352586274942673113L;
    /**
     * 默认金钱数,单位分
     */
    private Long moneyFen = 0L;

    /**
     * 转换元
     * 
     * @param yuan
     * @return
     */
    public Money convertYuan(long yuan) {
        moneyFen = yuan * 100;
        return this;
    }

    /**
     * 转换分
     * @return
     */
    public Money convertFen(long fen) {
        moneyFen = fen;
        return this;
    }

    /**
     * 获取银联需要的价钱信息
     * 
     * @return
     */
    public String getChinaPay() {

        String money = String.valueOf(moneyFen);
        //不能超过12位
        if (moneyFen < 0 || money.length() > 12) {
            throw new PayClientException(ErrorCodeEnum.MONEY_ERROR);
        }
        while (money.length() < 12) {
            money = "0"+money;
        }
        return money;
    }
    
    public String getChinapnrPay(){
        DecimalFormat format = new DecimalFormat("##0.00");
        return format.format(BigDecimal.valueOf(moneyFen).movePointLeft(2));
    }
    /**返回long金钱*/
    public Long getMoneyFen() {
        return moneyFen;
    }

}
